//
//  ImagesCollectionViewCell.m
//  RBIOSBase
//
//  Created by ren on 28/09/2017.
//  Copyright © 2017 bryan. All rights reserved.
//

#import "ImagesCollectionViewCell.h"
#import "ImageDownloader.h"
#import "CommonDefine.h"
#import <SDWebImage/UIImageView+WebCache.h>

@implementation ImagesCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setImageURL:(NSString *)imageURL
{
	[self.imageView setImage:nil];
	_imageURL = imageURL;
//	[self sdWebImage];
	[self.imageView sd_setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:nil options:SDWebImageProgressiveDownload];
}

- (void)sdWebImage
{
	ImageDownloader *imageDownloader = [ImageDownloader new];
	imageDownloader.reciverImage = ^(NSData *data, NSString *urlKey) {
		UIImage *image = [UIImage imageWithData:data];
		dispatch_main_async_safe(^{
			if (_imageURL && urlKey && ![_imageURL isEqualToString:@""] && ![urlKey isEqualToString:@""] && [_imageURL isEqualToString:urlKey])
			{
				[self.imageView setImage:image];
			}
		});
	};
	[imageDownloader loadFromURLKey:self.imageURL];

//	[imageDownloader genURLSession];
}

@end
